Skip to content

Interval formatters #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 90 commits into from
Jun 27, 2017
Merged

Interval formatters #17

merged 90 commits into from
Jun 27, 2017

Conversation

safareli
Copy link
Contributor

@safareli safareli commented Apr 5, 2017

bower.json Outdated
"purescript-fixed-points": "^4.0.0",
"purescript-datetime": "^3.0.0"
"purescript-datetime": "git://github.com/safareli/purescript-datetime.git#interval",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 should be changed after purescript/purescript-datetime#52 is merged

@safareli
Copy link
Contributor Author

@cryogenian can you take another look.

@safareli safareli changed the title WIP Interval formatters Interval formatters Jun 26, 2017
@safareli
Copy link
Contributor Author

@cryogenian can you take another look

Copy link
Member

@cryogenian cryogenian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two small picky things feel free to merge with or without them :)


exactLength ∷ ∀ e. ReaderT { maxLength ∷ Int, length ∷ Int | e } (Either String) Unit
exactLength = ask >>= \({maxLength, length}) → if maxLength /= length
then lift $ Left $ "Expected " <> (show maxLength) <> " digits but got " <> (show length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both branches have lift you can put it before if


validateRange ∷ ∀ e. Int → Int → ReaderT { num ∷ Int | e } (Either String) Unit
validateRange min max = ask >>= \({num}) → if num < min || num > max
then lift $ Left $ "Number is out of range [ " <> (show min) <> ", " <> (show max) <> " ]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same two lifts

-- |
-- | The `Lazy` constraint is used to generate the result lazily, to ensure
-- | termination.
takeSome :: forall f a. Alternative f => Z.Lazy (f (List.List a)) => Int -> f a -> f (List.List a)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent arrows and forall symbols here

→ P.ParserT String m Int
parseInt maxLength validators errMsg = do
ds ← takeSome maxLength parseDigit
let length = List.length ds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double let

YearTwoDigits → _{year = _} `modifyWithParser`
(parseInt 2 exactLength "Incorrect 2-digit year")
YearAbsolute → _{year = _} `modifyWithParser`
(pure (*)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lift2?

, minute: Just $ fromEnum $ T.minute t
, second: Just $ fromEnum $ T.second t
, millisecond: Just $ fromEnum $ T.millisecond t
, meridiem: (Nothing ∷ Maybe Meridiem)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this annotation still needed?

parseIsoDuration = do
dur ← parseDuration
case mkIsoDuration dur of
Left errs → let errorStr = intercalate ", " (prettyError <$> errs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda non-common formatting. Could you put let on the next line?

notEmpty p str = p >>= \x → if x == mempty then P.fail str else pure x

mkComponentsParser ∷ Array (Tuple (Number → I.Duration) String) → P.Parser String I.Duration
mkComponentsParser arr = p `notEmpty` ("None of valid duration components (" <> (show $ snd <$> arr) <> ") were present")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest using operator instead of infix function here. Like <?> in strongcheck. Or prefix func application. It's a bit mistyfying in that case, I mean infix notEmpty, maybe msgIfEmpty or something else.
Compare:

p <:?:> "Critical Error!!!" 
nonEmptyParser p "Critical Error!!!"
p `messageIfInputIsEmpty` "Critical Error!!!"

@safareli safareli merged commit 6159472 into purescript-contrib:master Jun 27, 2017
@safareli safareli deleted the interval branch August 5, 2017 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants